<template>
  <div>
	  
	  
	  
	 <Card :bordered="false" shadow="never" class="ivu-mt" :body-style="{padding:0}">
	    <div class="padding-add">
	      <Form
	          ref="levelFrom"
	          :model="groupFrom"
	          :label-width="labelWidth"
	          :label-position="labelPosition"
	          inline
	          @submit.native.prevent
	      >
	        <FormItem label="代理地址：" label-for="title">
	          <Input
	              clearable
	              v-model="groupFrom.provincials"
	              placeholder="请输入代理地址"
	              class="form_content_width"
	          />
	        </FormItem>
			
			<FormItem label="用户ID：" label-for="title">
			  <Input
			      clearable
			      v-model="groupFrom.uid"
			      placeholder="请输入用户ID"
			      class="form_content_width"
			  />
			</FormItem>
	        <FormItem>
	          <Button type="primary" @click="userSearchs">查询</Button>
	        </FormItem>
	      </Form>
	    </div>
	  </Card>
	  
	  
	  
	  
	
	  
    <Card :bordered="false" shadow="never" class="ivu-mt">
      <Row>
        <Col v-bind="grid">
        
		  <Button class="ml10" type="primary" @click="dialogVisible=true">添加代理</Button>
        </Col>
      </Row>
	  
      <vxe-table
        :data="groupLists"
        ref="table"
        class="mt14"
        v-loading="loading"
        highlight-current-row
        no-userFrom-text="暂无数据"
        no-filtered-userFrom-text="暂无筛选结果"
      >
       
		
		
		
		 <vxe-column field="id" title="ID" min-width="90"></vxe-column>
		 
		 <vxe-column field="nickname" title="昵称" min-width="90"></vxe-column>
		 
		 
		  <vxe-column field="uid" title="用户id" min-width="90"></vxe-column>
		  
		  
		  <vxe-column field="isMember" title="代理级别" min-width="90">
		    <template v-slot="{ row }">
		      <span v-if="row.level==1">省级</span>
		       <span v-if="row.level==2">市级</span>
		        <span v-if="row.level==3">区级</span>
		        <!-- <span v-if="row.level==4">街道</span> -->
		    </template>
		  </vxe-column>
		  
		 <vxe-column field="provincials" title="代理地址" min-width="180"></vxe-column>
		 <vxe-column field="add_time" title="时间" min-width="90"></vxe-column>
		 
		 
		<!-- 

		
	
		<el-table-column label="代理级别" min-width="80">
		  <template slot-scope="scope">
		    <span v-if="scope.row.level==1">省级</span>
			 <span v-if="scope.row.level==2">市级</span>
			  <span v-if="scope.row.level==3">区级</span>
			   <span v-if="scope.row.level==4">街道</span>
		  </template>
		</el-table-column>
	
		<el-table-column label="代理地址" min-width="80">
		  <template slot-scope="scope">
		    <span>{{ scope.row.provincials }}</span>
		  </template>
		</el-table-column>
		
		
		<el-table-column label="时间" min-width="80">
		  <template slot-scope="scope">
		    <span>{{ scope.row.add_time }}</span>
		  </template>
		</el-table-column>
        <el-table-column fixed="right" label="操作" width="100">
          <template slot-scope="scope">
            <a @click="edit(scope.row.id)">修改</a>
            <el-divider direction="vertical"></el-divider>
            <a @click="del(scope.row, '删除服务中心', scope.$index)">删除</a>
          </template>
        </el-table-column> -->
		
		<vxe-column field="action" title="操作" align="center" width="180" fixed="right">
			<!-- slot-scope="scope" -->
		  <template  v-slot="{ row }" >
		  <!--  <a @click="edit(row.id)">修改</a> -->
		   
			
			  <Divider type="vertical" />
			  
		    <a @click="del(row.id, '删除服务中心', row.$index)">删除</a>
		  </template>
		</vxe-column> 
		
	
		
		
		
      </vxe-table>
      <div class="acea-row row-right page">
        <vxe-pager
          v-if="total"
          :total="total"
          :page.sync="groupFrom.page"
          :limit.sync="groupFrom.limit"
          @pagination="getList"
        >
		</vxe-pager>
      </div>
    </Card>
	
	
	<Card :bordered="false" dis-hover class="ivu-mt" v-if="false">
	
	  <vxe-table :columns="thead" :data="tbody" ref="table" :loading="loading" highlight-row no-userFrom-text="暂无数据" no-filtered-userFrom-text="暂无筛选结果">
		<template slot-scope="scope" slot="image">
		  <viewer>
			<div style="width:100px;height:50px">
			  <img style="width:100%;height:100%" v-lazy="row.url">
			</div>
		  </viewer>
		</template>
		<template slot-scope="scope" slot="btns">
		  <a @click="changeMenu(row,2,index)">删除</a>
		</template>
	
	  </vxe-table>
	  <div class="acea-row row-right page">
	
				<vxe-pager
				  v-if="total"
				  :total="total"
				  :page.sync="tablePage.page"
				  :limit.sync="tablePage.limit">
				 </vxe-pager>
			</div>
	</Card>
	<!-- dialogVisible -->
	<!-- :before-close="handleClose" -->
	<!-- visible.sync="false" -->
	<Modal title="添加代理"  width="50%"   v-model='dialogVisible'  @on-cancel="handleClose" >
	  <div>
	    <div class="block">
	      <span>代理级别：</span>
	      <Select v-model="agencyFrom.level" placeholder="请选择" @on-change="handleChange">
	        <Option v-for="item in options1" :key="item.value" :label="item.label" :value="item.value">
	        </Option>
	      </Select>
	    </div>
	    <div class="block" style="margin-top:15px">
	      <span>选择地址：</span>
		<!-- {{city2}} -->
	    
		<!--  {{city2}} -->
		  
		  <el-cascader
			  ref="refSubCat"
		      placeholder="请选择地区"
		      class="input-add"
		      size="mini"
		      v-model="value3"
		      :options="city2"
			  filterable
		      @change="handleChange1"
		  >
		  </el-cascader>
		  
		  
		  
		  
		  
		  
		  
		  
		  
		  
		  <Card :bordered="false" shadow="never" class="ivu-mt" :body-style="{padding:0}">
		     <div class="padding-add">
		       <Form
		           ref="levelFrom"
		           :model="groupFromDaili"
		           :label-width="labelWidth"
		           :label-position="labelPosition"
		           inline
		           @submit.native.prevent
		       >
		       
		  			<FormItem label="用户UID：" label-for="title">
		  			  <Input
		  			      clearable
		  			      v-model="userFrom.uid"
		  			      placeholder="请输入用户UID"
		  			      class="form_content_width"
		  			  />
		  			</FormItem>
					
					
					<FormItem label="用户手机号：" label-for="title">
					  <Input
					      clearable
					      v-model="userFrom.phone"
					      placeholder="请输入用户手机号"
					      class="form_content_width"
					  />
					</FormItem>
		         <FormItem>
		           <Button type="primary" @click="userSearchsDaili">查询</Button>
		         </FormItem>
		       </Form>
		     </div>
		   </Card>
		   
		   
		   
		  
		  
	    </div>
	  </div>
	  
	 <!-- <Cascader
	      :data="brandData"
	  
	      v-model="artFrom.brand_id"
	      
	    
	   
	  ></Cascader> -->
	  
	  
	 <!-- <el-cascader
	      placeholder="请选择商品分类"
	      class="input-add"
	      size="mini"
	      v-model="artFrom.cate_id"
	      :options="data1"
	  >
	  </el-cascader> -->
	  
	  
	
	  <vxe-table ref="xTable" class="mt25" :loading="loading" row-id="uid" :expand-config="{accordion: true}" @radio-change="checkboxItem" :data="userLists">
	    <vxe-column type="" width="0"></vxe-column>
	    <vxe-column type="radio" field="nickname" title="选择用户" width="100">
	      
	    </vxe-column>
	    <vxe-column field="uid" title="UID" width="60"></vxe-column>
	    <vxe-column field="avatars" title="头像" width="50" height="50" >
	      <template v-slot="{ row }">
	        <viewer>
	          <div class="tabBox_img">
	            <img v-lazy="row.avatar" height="50px;"/>
	          </div>
	        </viewer>
	      </template>
	    </vxe-column>
	    <vxe-column field="nickname" title="昵称" min-width="100">
	      <template v-slot="{ row }">
	        <div class="acea-row">
	          <Icon type="md-male" v-show="row.sex === '男'" color="#2db7f5" size="15" class="mr5" />
	          <Icon type="md-female" v-show="row.sex === '女'" color="#ed4014" size="15" class="mr5" />
	          <div v-if="row.delete_time != null" style="color:#ed4014;">{{row.nickname}} (已注销)</div>
	          <div v-else v-text="row.nickname"></div>
	        </div>
	      </template>
	    </vxe-column>
		
		
		 <vxe-column field="phone" title="手机号码" min-width="100"></vxe-column>
		 
		 
	    <vxe-column field="level" title="用户等级" min-width="100"></vxe-column>
		
		
		 
		<!--  <vxe-column field="level" title="用户等级" min-width="100"></vxe-column> -->
		  
		  
	
	  </vxe-table>
	  <vxe-pager class="mt20" border size="medium" :page-size="userFrom.limit" :current-page="userFrom.page" :total="total1" :layouts="['PrevPage', 'JumpNumber', 'NextPage', 'FullJump', 'Total']" @page-change="pageChange1">
	  </vxe-pager>
	  <div class="btns">
	    <Button type="primary" plain @click="dialogVisible=false" style='margin-right:20px;'>取消</Button>
	    <Button type="success" plain @click="addok">确定</Button>
	  </div>
	  
	  <div slot="footer"></div>
	</Modal>
	
	
	<Modal title="提示" v-model="dialogVisible2" width="30%">
	  <span>确定删除这条数据嘛</span>
	  <span slot="footer" class="dialog-footer">
	    <Button @click="dialogVisible2 = false">取 消</Button>
	    <Button type="primary" @click="deteleItem">确 定</Button>
	  </span>
	</Modal>
	
	
	
	
	
  </div>
</template>

<script>

// import {
 
//   userGroupApi,
 
// } from "@/api/user";

import { mapState } from 'vuex';
import { userAgentApi, agentAddApi,getAreaAgent,getAddress,userList,getAgency,userGroupApi,deleteAreaAgent} from '@/api/user';


import {
  
  brandList,
 cascaderListApi,
} from '@/api/product';


export default {
  name: "user_group",

  components: {
  
  
  },
  data() {
    return {
      groupList: [],
	
	   grid: {
	          xl: 7,
	          lg: 7,
	          md: 12,
	          sm: 24,
	          xs: 24,
	        },
	        loading: false,
	  
	        groupFrom: {
	  		  uid:'',
	  		  provincials: '',
	          page: 1,
	          limit: 15,
	        },
			
			groupFromDaili:{
				uid:'',
				phone:''
			},
	        groupLists: [],
	        total: 0,
			add_daili:true,
	  	  
	  	  
	  	  
	  	  
	  	   brandData:[],
	  	  artFrom: {
	  	    page: 1,
	  	    limit: 15,
	  	    cate_id: "",
	  	    type: "1",
	  	    store_name: "",
	  	    excel: 0,
	  	    supplier_id: "",
	  	    store_id:"",
	  	    brand_id:[],
	  	    store_label_id:[]
	  	  },
	  	   data1: [],
	  	  
	  	  
	  	  
	  	  
	  	  
	  	  
	  	  
	  	  
	  	  
	  	  
	  	  
	  	  //新增处理
	  	  otProps: {
	  	    value: "id",
	  	    label: "name",
	  	    children: "city",
	  	  },
	  	  dialogVisible: false,
	  	  thead: [
	  	    {
	  	      title: "ID",
	  	      key: "id",
	  	      minWidth: 50,
	  	    },
	  	    {
	  	      title: "昵称",
	  	      minWidth: 50,
	  	      render: (h, params) => {
	  	        return h("span", params.row.nickname);
	  	      },
	  	    },
	  		
	  		{
	  		  title: "用户id",
	  		  key: "uid",
	  		  minWidth: 50,
	  		},
	  		
	  	    {
	  	      title: "代理级别",
	  	      minWidth: 100,
	  	      ellipsis: true,
	  	  
	  	      render: (h, params) => {
	  	        let level;
	  	        if (params.row.level == 1) {
	  	          level = "省级";
	  	        } else if (params.row.level == 2) {
	  	          level = "市级";
	  	        }  else if (params.row.level == 3){
	  	          level = "县/区级";
	  	        }
				// else{
	  	// 			level = "街道";
	  	// 		}
	  	        return h("span", level);
	  	      },
	  	    },
	  	    // {
	  	    //   title: "分配比例",
	  	    //   minWidth: 80,
	  	    //   render: (h, params) => {
	  	    //     return h("span", params.row.odds);
	  	    //   },
	  	    // },
	  	    {
	  	      title: "代理地址",
	  	      minWidth: 100,
	  	      ellipsis: true,
	  	      render: (h, params) => {
	  	        return h("span", params.row.provincials);
	  	      },
	  	    },
	  	    {
	  	      title: "时间",
	  	      minWidth: 80,
	  	      render: (h, params) => {
	  	        return h("span", params.row.create_time);
	  	      },
	  	    },
	  	  
	  	    {
	  	      title: "操作",
	  	      key: "update_time",
	  	      minWidth: 90,
	  	      slot: "btns",
	  	      // render: (h, params) => {
	  	      //     return h("span", params.row.update_time);
	  	      // },
	  	    },
	  	  ],
	  	  tbody: [],
	  	  loading: false,
	  	  total: 0,
	  	  total1: 0,
	  	  formValidate: {
	  	    phone: "",
	  	    create_time: "",
	  	  },
	  	  options: {
	  	    shortcuts: [
	  	      {
	  	        text: "今天",
	  	        value() {
	  	          const end = new Date();
	  	          const start = new Date();
	  	          start.setTime(
	  	            new Date(
	  	              new Date().getFullYear(),
	  	              new Date().getMonth(),
	  	              new Date().getDate()
	  	            )
	  	          );
	  	          return [start, end];
	  	        },
	  	      },
	  	      {
	  	        text: "昨天",
	  	        value() {
	  	          const end = new Date();
	  	          const start = new Date();
	  	          start.setTime(
	  	            start.setTime(
	  	              new Date(
	  	                new Date().getFullYear(),
	  	                new Date().getMonth(),
	  	                new Date().getDate() - 1
	  	              )
	  	            )
	  	          );
	  	          end.setTime(
	  	            end.setTime(
	  	              new Date(
	  	                new Date().getFullYear(),
	  	                new Date().getMonth(),
	  	                new Date().getDate() - 1
	  	              )
	  	            )
	  	          );
	  	          return [start, end];
	  	        },
	  	      },
	  	      {
	  	        text: "最近7天",
	  	        value() {
	  	          const end = new Date();
	  	          const start = new Date();
	  	          start.setTime(
	  	            start.setTime(
	  	              new Date(
	  	                new Date().getFullYear(),
	  	                new Date().getMonth(),
	  	                new Date().getDate() - 6
	  	              )
	  	            )
	  	          );
	  	          return [start, end];
	  	        },
	  	      },
	  	      {
	  	        text: "最近30天",
	  	        value() {
	  	          const end = new Date();
	  	          const start = new Date();
	  	          start.setTime(
	  	            start.setTime(
	  	              new Date(
	  	                new Date().getFullYear(),
	  	                new Date().getMonth(),
	  	                new Date().getDate() - 29
	  	              )
	  	            )
	  	          );
	  	          return [start, end];
	  	        },
	  	      },
	  	      {
	  	        text: "本月",
	  	        value() {
	  	          const end = new Date();
	  	          const start = new Date();
	  	          start.setTime(
	  	            start.setTime(
	  	              new Date(new Date().getFullYear(), new Date().getMonth(), 1)
	  	            )
	  	          );
	  	          return [start, end];
	  	        },
	  	      },
	  	      {
	  	        text: "本年",
	  	        value() {
	  	          const end = new Date();
	  	          const start = new Date();
	  	          start.setTime(
	  	            start.setTime(new Date(new Date().getFullYear(), 0, 1))
	  	          );
	  	          return [start, end];
	  	        },
	  	      },
	  	    ],
	  	  },
	  	  timeVal: [],
	  	  tablePage: {
	  	    page: 1,
	  	    limit: 15,
	  	  },
	  	  userLists: [],
	  	  selectionList: [],
	  	  userFrom: {
	  	    label_id: "",
	  	    user_type: "",
	  	    status: "",
	  	    sex: "",
	  	    is_promoter: "",
	  	    country: "",
	  	    isMember: "",
	  	    pay_count: "",
	  	    user_time_type: "",
	  	    user_time: "",
	  	    nickname: "",
	  	    province: "",
	  	    city: "",
	  	    page: 1,
	  	    limit: 10,
	  	    level: "",
	  	    group_id: "",
	  	    field_key: "",
	  	  },
	  	  field_key: "",
	  	  isAll: 0,
	  	  checkUidList: [],
	  	  dataLabel: [],
	  	  options1: [
	  	    {
	  	      value: "1",
	  	      label: "省",
	  	    },
	  	    {
	  	      value: "2",
	  	      label: "市",
	  	    },
	  	    {
	  	      value: "3",
	  	      label: "区/县",
	  	    },
	  		// {
	  		//   value: "4",
	  		//   label: "街道",
	  		// },
	  	  ],
	  	  level: "",
	  	  addList: [],
	  	  value3: "",
	  	  isDisabled: true,
	  	  city1: [],
	  	  city2: [],
	  	  agencyFrom: {
	  	    uid: "",
	  	    level: "",
	  	    provincials: "",
	  	    province: "",
	  	    city: "",
	  	    area: "",
	  		jiedao: "",
	  	  },
	  	  dialogVisible2: false,
	  	  row: null,
    
    };
  },
  watch: {
    selectionList(value) {
         let arr = value.map((item) => item.uid);
         this.array_ids = arr;
         this.user_ids = arr.join();
       },
       userLists: {
         deep: true,
         handler(value) {
           value.forEach((item) => {
             this.selectionList.forEach((itm) => {
               if (itm.uid === item.uid) {
                 item.checkBox = true;
               }
             });
           });
           const arr = this.userLists.filter((item) => item.checkBox);
           if (this.userLists.length) {
             this.checkBox = this.userLists.length === arr.length;
           } else {
             this.checkBox = false;
           }
         },
       },
  },
  computed: {
   ...mapState('media', ['isMobile']),
       labelWidth() {
         return this.isMobile ? undefined : '80px';
       },
       labelPosition() {
         return this.isMobile ? 'top' : 'left';
       },
  },
  
  mounted() {
    this.userGroup();
  },
    
    created() {
		this.getList();
		this.getListUser();
		// alert('yes');
		//新增处理
		// this.getAreaAgent();
		// alert('yes');
		// getAddress().then((res) => {
		// 	// alert('yes');
		//   // console.log('res.data',res.data);
		//   this.city1 = res.data;
		// });  
		// let addressInfo = [];
	
		getAddress()
		  .then(async (res) => {
			
			  // alert('yes');
			    this.city1 = res.data;
		});  	  
		
		 this.getBrandList();
		this.goodsCategory();
    },
  methods: {
	  // 商品分类；
	  goodsCategory() {
	    // treeListApi(1).then(res => {
	    //     this.treeSelect = res.data;
	    // }).catch(res => {
	    //     this.$Message.error(res.msg);
	    // })
	    cascaderListApi(1)
	        .then((res) => {
	          this.data1 = res.data;
	  		
	  		console.log('this.brandData',this.brandData);
	  		console.log('props',this.props);
	        })
	        .catch((res) => {
	          this.$Message.error(res.msg);
	        });
	  },
	  // 表格搜索
	  userSearchs(e) {
	    // this.allReset();
	    // this.artFrom.page = 1;
	    // this.formSelection = [];
	    // this.goodHeade();
	    // this.getDataList();
	  },
	  // 品牌列表
	  getBrandList(){
	    brandList().then(res=>{
	      this.brandData = res.data
		  console.log('this.brandData',this.brandData);
	    }).catch(err=>{
	      this.$Message.error(err.msg);
	    })
	  },
    // 添加
       add() {
         this.$modalForm(agentAddApi(0)).then(() => this.getList());
       },
   	// 表格搜索
   	userSearchs() {
   	  this.groupFrom.page = 1;
   	  this.getList();
   	},
	
	// 表格搜索
		userSearchsDaili() {
		  this.groupFromDaili.page = 1;
		  this.userFrom.page=1;
		  // this.userFrom.uid=;
		  this.getListUser();
		  
		},
       // 服务中心列表
       getList() {
         this.loading = true;
         userAgentApi(this.groupFrom)
           .then(async (res) => {
             let data = res.data;
             this.groupLists = data.list;
			 console.log('data.list的值',data.list);
             this.total = data.count;
             this.loading = false;
           })
           .catch((res) => {
             this.loading = false;
             this.$message.error(res.msg);
           });
   		/*获取用户列表*/
       },
   	getListUser(){
   		this.loading = true;
   		let activeIds = [];
   		this.dataLabel.forEach((item) => {
   		  activeIds.push(item.id);
   		});
   		this.userFrom.label_id = activeIds.join(",") || "";
   		this.userFrom.user_type = this.userFrom.user_type || "";
   		this.userFrom.status = this.userFrom.status || "";
   		this.userFrom.sex = this.userFrom.sex || "";
   		this.userFrom.is_promoter = this.userFrom.is_promoter || "";
   		this.userFrom.country = this.userFrom.country || "";
   		this.userFrom.user_time_type = this.userFrom.user_time_type || "";
   		this.userFrom.pay_count = this.userFrom.pay_count || "";
   		// this.userFrom.label_id = this.userFrom.label_id || "";
   		this.userFrom.field_key = this.field_key === "all" ? "" : this.field_key;
   		this.userFrom.level =
   		  this.userFrom.level === "all" ? "" : this.userFrom.level;
   		this.userFrom.group_id =
   		  this.userFrom.group_id === "all" ? "" : this.userFrom.group_id;
   		userList(this.userFrom)
   		  .then(async (res) => {
   			let data = res.data;
   			data.list.forEach((item) => {
   			  item.checkBox = false;
   			});
   			this.userLists = data.list;
   			this.total1 = data.count;
   			this.loading = false;
   			this.$nextTick(function () {
   			  if (this.isAll == 1) {
   				this.selectionList = this.userLists;
   				// if (this.isCheckBox) {
   				//   this.$refs.xTable.setAllCheckboxRow(true);
   				// } else {
   				//   this.$refs.xTable.setAllCheckboxRow(false);
   				// }
   			  } else {
   				// if (!this.checkUidList.length) {
   				//   this.$refs.xTable.setAllCheckboxRow(false);
   				// }
   			  }
   			});
   		  })
   		  .catch((res) => {
   			this.loading = false;
   			this.$Message.error(res.msg);
   		  });
   	  	
   	},
	getAreaAgent() {
		  // this.loading = true;
		  // let data = {
		  //   page: this.tablePage.page,
		  //   limit: this.tablePage.limit,
		  // };
		  
		  this.getList();
		  // // alert('yes');
		  // console.log(data);
		  // getAreaAgent(data)
		  //   .then((res) => {
			 
		  //     console.log('res.info的值',res);
		  //     this.loading = false;
		  //     const { list, count } = res.data;
		  //     this.tbody = list;
		  //     this.total = count;
		  //   })
		  //   .catch((err) => {
		  //     this.loading = false;
		  //     this.$Message.error(err.msg);
		  //   });
		},
		
	    // 修改
	    edit(id) {
	      this.$modalForm(agentAddApi(id)).then(() => this.getList());
	    },
		
		del(id, tit) {
			// console.log('id',id);
			// consolo.log('tit',tit);
		 // let delfromData = {
		 //   title: tit,
		 //    url: `user/user_agent/del/${id}`,
		 //   method: "DELETE",
		 //   ids: "",
		 // };
		 // this.$modalSure(delfromData)
		 //   .then((res) => {
		 //     this.$Message.success(res.msg);
		 //     // this.$refs.menusFrom.getAddFrom();
		 //     this.getData();
		 //   })
		 //   .catch((err) => {
		 //     this.$Message.error(err.msg);
		 //   });
		   
		 console.log('id',id);
		 let self = this
		 this.$Modal.confirm({
		     title: '删除确认',
		     content: '您确定删除该服务商吗。',
		     onOk: () => {
		         // self.logoutKefu({
		         //     confirm: false,
		         //     vm: self
		         // });
				 deleteAreaAgent(id).then(res=>{
				   // this.brandData = res.data
				   // console.log('this.brandData',this.brandData);
				     this.$Message.success('删除成功');
					  this.getList();
				 }).catch(err=>{
				   this.$Message.error(err.msg);
				 })
				
		     },
		     onCancel: () => {
		 
		     }
		 });
		},
		
	    // 删除
	  //   del(row, tit, num) {
			// // alert('删除');
	  //     // let delfromData = {
	  //     //   title: tit,
	  //     //   num: num,
	  //     //   url: `user/user_agent/del/${row.id}`,
	  //     //   method: 'DELETE',
	  //     //   ids: '',
	  //     // };
	  //     // this.$modalSure(delfromData)
	  //     //   .then((res) => {
	  //     //     this.$message.success(res.msg);
	  //     //     this.groupLists.splice(num, 1);
	  //     //     this.getList();
	  //     //   })
	  //     //   .catch((res) => {
	  //     //     this.$message.error(res.msg);
	  //     //   }); 
		  
		 //  // deleteAreaAgent(row.id)
		 //  //   .then(async (res) => {
		 //  // 	  // alert('yes');
		 //  // 	    this.city1 = res.data;
		 //  // });  	  
		  
		 // let delfromData = {
		 //   title: tit,
		 //   num: num,
		 //   url:`user/user_agent/del/${row.id}`,
		 //   method: "DELETE" ,
		 //   // url: `user/del_level/${row.uid}`,
		 //   // method: 'DELETE',
		 //   ids: "",
		 // };
		 // this.$modalSure(delfromData)
		 //     .then((res) => {
		 //       this.$Message.success(res.msg);
		 //       this.getList();
		 //     })
		 //     .catch((res) => {
		 //       this.$Message.error(res.msg);
		 //     });
			
	  //   },
		//新增所有方法
		
		
			onchangeTime(e) {
			  this.timeVal = e;
			  this.formValidate.create_time = this.timeVal[0]
			    ? this.timeVal.join("-")
			    : "";
			  this.tablePage.page = 1;
			  this.getAreaAgent();
			},
			getAreaAgent() {
			  // this.loading = true;
			  // let data = {
			  //   page: this.tablePage.page,
			  //   limit: this.tablePage.limit,
			  // };
			  this.getList();
			  // getAreaAgent(data)
			  //   .then((res) => {
			  //     console.log(res);
			  //     this.loading = false;
			  //     const { list, count } = res.data;
			  //     this.tbody = list;
			  //     this.total = count;
			  //   })
			  //   .catch((err) => {
			  //     this.loading = false;
			  //     this.$Message.error(err.msg);
			  //   });
			},
			// 分页
			pageChange(index) {
			  this.tablePage.page = index;
			  this.getUserEggList();
			},
			pageChange1(index) {
				console.log('index',index);
			  this.userFrom.page = index.currentPage;
			  this.getList();
			  this.getListUser();
			},
			edit(row) {
			  console.log(row);
			  this.dialogVisible = true;
			  // this.agencyFrom.odds = row.odds;
			  this.value3 = [];
			  if (String(row.province).length > 0) {
			    this.value3.push(String(row.province));
			  }
			  if (String(row.city).length > 0) {
			    this.value3.push(String(row.city));
			  }
			  if (String(row.area).length > 0) {
			    this.value3.push(String(row.area));
			  }
			  if (String(row.jiedao).length > 0) {
			    this.value3.push(String(row.jiedao));
			  }
			  // alert('yes');
			  // this.agencyFrom.odds = row.odds
			},
			changeMenu(row) {
			 // this.dialogVisible2 = true;
			  console.log(row);
			  this.row = row;
			},
			handleClose() {
			  this.dialogVisible = false;
			},
			checkboxAll() {
			  // 获取选中当前值
			  let obj2 = this.$refs.xTable.getCheckboxRecords(true);
			  // 获取之前选中值
			  let obj = this.$refs.xTable.getCheckboxReserveRecords(true);
			  obj = obj.concat(obj2);
			  let uids = [];
			  obj.forEach((item) => {
			    uids.push(parseInt(item.uid));
			  });
			  this.checkUidList = uids;
			  if (!obj2.length) {
			    this.isCheckBox = false;
			  }
			},
			checkboxItem(e) {
			  console.log(e);
			  this.checkUidList = [];
			  let uid = parseInt(e.rowid);
			  let index = this.checkUidList.indexOf(uid);
			  // if (index !== -1 && this.isAll == 0) {
			  //   this.checkUidList = this.checkUidList.filter((item) => item !== uid);
			  // } else {
			  this.checkUidList.push(uid);
			  this.agencyFrom.uid = uid;
			  // }
			},
			allPages(e) {
			  this.isAll = e;
			  if (e == 0) {
			    this.$refs.xTable.toggleAllCheckboxRow();
			    this.checkboxAll();
			  } else {
			    if (!this.isCheckBox) {
			      this.$refs.xTable.setAllCheckboxRow(true);
			      this.isCheckBox = true;
			      this.isAll = 1;
			    } else {
			      this.$refs.xTable.setAllCheckboxRow(false);
			      this.isCheckBox = false;
			      this.isAll = 0;
			    }
			    this.checkUidList = [];
			  }
			},
			
			handleChange(e) {
			  console.log('e的值',e);  
			  // this.getData(e);
		
			  this.city2 = this.getData(e);
			},
			handleChange1(e) {
				// alert('yes');
				// alert('yes');
			  // console.log(e);
			  // console.log(this.$refs["refSubCat"].getCheckedNodes()[0].pathLabels);
			  this.agencyFrom.province = "";
			  this.agencyFrom.city = "";
			  this.agencyFrom.area = "";
			  this.agencyFrom.jiedao = "";
			  this.agencyFrom.provincials = this.$refs["refSubCat"]
			    .getCheckedNodes()[0]
			    .pathLabels.join("/");
				
				console.log('e的值',e);
			  if (this.agencyFrom.level == 1) {
			    this.agencyFrom.province = e[0];
			  } else if (this.agencyFrom.level == 2) {
			    this.agencyFrom.province = e[0];
			    this.agencyFrom.city = e[1];
			  } else if (this.agencyFrom.level == 3) {
			    this.agencyFrom.province = e[0];
			    this.agencyFrom.city = e[1];
			    this.agencyFrom.area = e[2];
			  }else if (this.agencyFrom.level == 4) {
			    this.agencyFrom.province = e[0];
			    this.agencyFrom.city = e[1];
			    this.agencyFrom.area = e[2];
				this.agencyFrom.jiedao = e[3];
			  }
			},
			getData(level) {
			  var data = this.city1;
			  console.log('getData的值',data);
			  var result = [];
			// alert(level);
			  if (level == 1 || level == 2 ) {
			    for (var i = 0; i < data.length; i++) {
			      var provinceData = {
			        // name: data[i].name,
			        // id: data[i].id,
					label: data[i].label,
					value: data[i].value,
			      };
			
			      if (level >= 2) {
			        provinceData.children = [];
			        for (var j = 0; j < data[i].children.length; j++) {
			          var cityData = {
			            // name: data[i].city[j].name,
			            // id: data[i].city[j].id,
						value: data[i].children[j].value,
						label: data[i].children[j].label,
			          };
			          provinceData.children.push(cityData);
			        }
			      }
			      result.push(provinceData);
			    }
			  }
			  console.log('level的值',level);
			  if (level == 1 || level == 2) {
				    console.log('no');
			    return result;
			  } else {
				  console.log('yes');
			    return this.city1;
			  }
			},
			addok() {
				// alert('yes');
			  if (this.agencyFrom.uid == "") {
			    // return this.$message({
			    //   message: "请选择用户",
			    //   type: "warning",
			    // });
				
				 return this.$Message.error('请选择用户');
				 
			  }
			  if (this.agencyFrom.level == "") {
			    // return this.$message({
			    //   message: "请选择代理级别",
			    //   type: "warning",
			    // });
				return this.$Message.error('请选择代理级别');
			  }
			  if (this.agencyFrom.province == "") {
			    // return this.$message({
			    //   message: "请选择地址",
			    //   type: "warning",
			    // });
				 return this.$Message.error('请选择地址');
			  }
			  // if (this.agencyFrom.odds == "") {
			  //   return this.$message({
			  //     message: "请填写返佣比例",
			  //     type: "warning",
			  //   });
			  // }
			  var that=this;
			    console.log('');
			  getAgency(this.agencyFrom, 0).then((res) => {
			    console.log(res);
				console.log('11111');
			    this.dialogVisible = false;
			    if ((res.code = 200)) {
			      this.agencyFrom = {
			        uid: "",
			        level: "",
			        provincials: "",
			        province: "",
			        city: "",
			        area: "",
					jiedao: "",
			      };
			      this.getAreaAgent();
			      return this.$message({
			        message: res.msg,
			        type: "success",
			      });
			    }else{
					console.log('res的值',res);
					return that.$message({
					  message: res.msg,
					  type: "warning",
					});
				}
			  }).catch((res) => {
				// this.loading = false;
				// return this.$Message.error(res.msg);
				return this.$message({
				  message: res.msg,
				  type: "error",
				});
			  });
			},
			deteleItem() {
			  getDelAreaAgent(this.row.id).then((res) => {
			    this.dialogVisible2 = false;
			    if ((res.status = 200)) {
			      this.getAreaAgent();
			      return this.$message({
			        message: res.msg,
			        type: "success",
			      });
			    }
			  });
			},
			
			
		
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
    userGroup() {
      let data = {
        page: 1,
        limit: "",
      };
      userGroupApi(data).then((res) => {
        this.groupList = res.data.list;
      });
    },    
    
 
  },
};
</script>


<style scoped lang="stylus"></style>
